package demo0;

/**
 * Created with IntelliJ IDEA
 * Description:多态：1、继承 2、重写 3、多态
 * User:恋恋
 * Date:2022-09-09
 * Time:10:23
 */
class Shape{
    public void draw(){
        System.out.println("画图形");
    }
    //向上转型的对象，不能访问未重写的方法
    public void function(){
        System.out.println("父类");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("画圆形");
    }
}
class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("画三角形");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("画矩形");
    }
}
public class Test {
    // 2、作为方法的参数
    public static void judge(Shape shape){
        shape.draw();
    }
    public static void main(String[] args) {
        judge(new Cycle());
        judge(new Rect());
        judge(new Triangle());
    }
    public static void main1(String[] args) {
        //向上转型：1、 直接赋值 2、作为方法的参数 3、作为方法的返回值
        Shape shape1=new Cycle();
        Shape shape2=new Triangle();
        Shape shape3=new Rect();
        shape1.draw();
        shape2.draw();
        shape3.draw();
       // shape1.function();
    }
}
